<script setup>
import { ref, reactive, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { getAllShowService, getShowByClassifyService } from '@/api/show'
import { isLikeService,insertLikeService,deleteLikeService } from '@/api/like'
import { getAllEthnicService } from '@/api/ethnic'

const tableData = reactive([])

const pageNum = ref(1)
const total = ref(20)
const pageSize = ref(10)

const nationalities = ref([])

async function getShowList() {
    tableData.length = 0
    nationalities.value = await getAllEthnicService().data;
    let result = await getAllShowService(pageNum.value, pageSize.value)
    // if (result.code === 0) {
    total.value = result.data.total
    tableData.values = result.data
    for (let i = 0; i < result.data.items.length; i++) {
        // console.log(result.data.items[i].id)
        let res = await isLikeService("show",result.data.items[i].id)
        result.data.items[i].isLike = res.data
        console.log(res)
        tableData.push(result.data.items[i])
    }
    console.log(tableData)
}
getShowList()


const onSizeChange = (size) => {
    pageSize.value = size
    getShowList()
}
const onCurrentChange = (num) => {
    pageNum.value = num
    getShowList()
}

const isThumbsUp = ref(false)

// const nationalities = await getAllEthnicService().data

const thumbs2Show = async (likeId) => {
    await insertLikeService("show",likeId)
    console.log("点赞成功")
    getShowList()
}

const thumbs1Show = async (likeId) => {
    await deleteLikeService("show",likeId)
    console.log("取消点赞成功")
    getShowList()
}

</script>



<template>
    <div style="padding: 30px;width: 100%;">
        <div class="container">
            <div class="item" v-for="item in tableData">
                <div class="mask-div">
                    <el-image style="height: 220px; " :src="item.url" fit="fill" />
                    <!-- <i class="el-icon-zoom-in" @click="seeImg"></i>
                    <i class="el-icon-delete" @click="deleteImg"></i> -->
                    <div class="mask">{{ item.detail }}</div>
                </div>
                <div>
                    <transition name="thumbs1">
                        <i class="far fa-thumbs-up" @click="thumbs2Show(item.id)" v-show="!item.isLike" />
                    </transition>
                    <transition name="thumbs2">
                        <i class="fas fa-thumbs-up" @click="thumbs1Show(item.id)" v-show="item.isLike" />
                    </transition>
                    <i>{{ item.likeCount }}</i>
                </div>
                
            </div>
        </div>

        <div style="margin: 10px 0;">
            <el-pagination v-model:current-page="pageNum" v-model:page-size='pageSize' :page-sizes="[5, 10, 20]"
                layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="onSizeChange"
                @current-change="onCurrentChange" />
        </div>
    </div>

</template>


<style scoped>
.avatar-uploader .avatar {
    width: 90px;
    height: 90px;
    display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #4a4b4d;
    width: 90px;
    height: 90px;
    text-align: center;
}

.container {
    width: 100%;
    overflow: auto;
    /* background-color: aqua; */
}

.item {
    float: left;
    box-sizing: border-box;
    padding: 20px;
}

.mask {
    position: absolute;
    width: 100%;
    height: 100%;
    bottom: 0;
    background: rgba(101, 101, 101, 0.7);
    color: #ffffff;
    opacity: 0;
    font-family: "楷体"
        /* line-height: 300px; */
}

.mask-div {
    position: relative;
}

.mask-div:hover .mask {
    opacity: 1;
    cursor: default;
}
</style>